﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Yipusoft.Account.BLL;
using Yipusoft.Account.Model;
using System.Collections.Generic;

public partial class System_PermissionCategoryNew : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["CategoryID"] == null)
            {
                ActionTitle.Text = "添加目录";
            }
            else
            {
                ActionTitle.Text = "编辑目录";
                BindData();
                CategoryID.ReadOnly = true;
            }
        }
    }
    private void BindData()
    {
        PermissionCategoryInfo category = Yipusoft.Account.BLL.PermissionCategory.GetPermissionCategory(Request.QueryString["CategoryID"]);
        CategoryID.Text = category.CategoryID;
        CategoryName.Text = category.CategoryName;
        Description.Text = category.Description;
    }
    private void Insert()
    {
        if (Yipusoft.Account.BLL.PermissionCategory.Exsits(CategoryID.Text))
        {
            Prompt.Text = "警告：该目录编码已存在！";
            return;
        }
        PermissionCategoryInfo category = new PermissionCategoryInfo();
        category.CategoryID = CategoryID.Text;
        category.CategoryName = CategoryName.Text;
        category.Description = Description.Text;
        Yipusoft.Account.BLL.PermissionCategory.Insert(category);
        Prompt.Text = "提示：添加成功！";
    }
    private void Update()
    {
        PermissionCategoryInfo category = Yipusoft.Account.BLL.PermissionCategory.GetPermissionCategory(Request.QueryString["CategoryID"]);
        category.CategoryName = CategoryName.Text;
        category.Description = Description.Text;
        Yipusoft.Account.BLL.PermissionCategory.Update(category);
        Prompt.Text = "提示：更新成功！";
    }
    protected void ButtonSave_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["CategoryID"] == null)
            Insert();
        else
            Update();
    }
}
